from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-03-31 14:02:08.116206
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 31, Mar, 2022
Time: 14:02:13
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.7671
Nobs: 612.000 HQIC: -49.1640
Log likelihood: 7395.96 FPE: 3.45674e-22
AIC: -49.4166 Det(Omega_mle): 2.98756e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.344404 0.065693 5.243 0.000
L1.Burgenland 0.106070 0.040276 2.634 0.008
L1.Kärnten -0.110742 0.021072 -5.255 0.000
L1.Niederösterreich 0.194525 0.084218 2.310 0.021
L1.Oberösterreich 0.118025 0.082955 1.423 0.155
L1.Salzburg 0.259001 0.042717 6.063 0.000
L1.Steiermark 0.039963 0.056390 0.709 0.479
L1.Tirol 0.105135 0.045489 2.311 0.021
L1.Vorarlberg -0.066765 0.040191 -1.661 0.097
L1.Wien 0.017297 0.073909 0.234 0.815
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.052527 0.140894 0.373 0.709
L1.Burgenland -0.037987 0.086382 -0.440 0.660
L1.Kärnten 0.042019 0.045193 0.930 0.352
L1.Niederösterreich -0.201973 0.180627 -1.118 0.263
L1.Oberösterreich 0.454541 0.177917 2.555 0.011
L1.Salzburg 0.282708 0.091617 3.086 0.002
L1.Steiermark 0.112819 0.120941 0.933 0.351
L1.Tirol 0.306411 0.097562 3.141 0.002
L1.Vorarlberg 0.026673 0.086200 0.309 0.757
L1.Wien -0.028989 0.158515 -0.183 0.855
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.196962 0.033554 5.870 0.000
L1.Burgenland 0.088473 0.020572 4.301 0.000
L1.Kärnten -0.007206 0.010763 -0.669 0.503
L1.Niederösterreich 0.243346 0.043016 5.657 0.000
L1.Oberösterreich 0.160099 0.042371 3.779 0.000
L1.Salzburg 0.039974 0.021819 1.832 0.067
L1.Steiermark 0.027202 0.028802 0.944 0.345
L1.Tirol 0.082744 0.023234 3.561 0.000
L1.Vorarlberg 0.054032 0.020529 2.632 0.008
L1.Wien 0.116347 0.037750 3.082 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.115484 0.033597 3.437 0.001
L1.Burgenland 0.042628 0.020598 2.069 0.038
L1.Kärnten -0.013086 0.010777 -1.214 0.225
L1.Niederösterreich 0.173282 0.043071 4.023 0.000
L1.Oberösterreich 0.334976 0.042425 7.896 0.000
L1.Salzburg 0.099876 0.021847 4.572 0.000
L1.Steiermark 0.112771 0.028839 3.910 0.000
L1.Tirol 0.090847 0.023264 3.905 0.000
L1.Vorarlberg 0.060648 0.020555 2.951 0.003
L1.Wien -0.017843 0.037799 -0.472 0.637
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.122604 0.062926 1.948 0.051
L1.Burgenland -0.045979 0.038580 -1.192 0.233
L1.Kärnten -0.045519 0.020184 -2.255 0.024
L1.Niederösterreich 0.138395 0.080671 1.716 0.086
L1.Oberösterreich 0.161594 0.079461 2.034 0.042
L1.Salzburg 0.284333 0.040918 6.949 0.000
L1.Steiermark 0.058922 0.054015 1.091 0.275
L1.Tirol 0.159728 0.043573 3.666 0.000
L1.Vorarlberg 0.097616 0.038499 2.536 0.011
L1.Wien 0.071084 0.070796 1.004 0.315
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.070193 0.049161 1.428 0.153
L1.Burgenland 0.025330 0.030140 0.840 0.401
L1.Kärnten 0.052968 0.015769 3.359 0.001
L1.Niederösterreich 0.192565 0.063024 3.055 0.002
L1.Oberösterreich 0.331004 0.062078 5.332 0.000
L1.Salzburg 0.035471 0.031967 1.110 0.267
L1.Steiermark 0.009784 0.042199 0.232 0.817
L1.Tirol 0.121686 0.034041 3.575 0.000
L1.Vorarlberg 0.066299 0.030077 2.204 0.028
L1.Wien 0.096211 0.055309 1.740 0.082
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.172942 0.059267 2.918 0.004
L1.Burgenland 0.004915 0.036336 0.135 0.892
L1.Kärnten -0.065905 0.019011 -3.467 0.001
L1.Niederösterreich -0.105244 0.075980 -1.385 0.166
L1.Oberösterreich 0.206028 0.074840 2.753 0.006
L1.Salzburg 0.054330 0.038539 1.410 0.159
L1.Steiermark 0.247009 0.050874 4.855 0.000
L1.Tirol 0.502329 0.041039 12.240 0.000
L1.Vorarlberg 0.063935 0.036260 1.763 0.078
L1.Wien -0.077651 0.066679 -1.165 0.244
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.156475 0.065696 2.382 0.017
L1.Burgenland -0.002340 0.040278 -0.058 0.954
L1.Kärnten 0.062481 0.021073 2.965 0.003
L1.Niederösterreich 0.168959 0.084223 2.006 0.045
L1.Oberösterreich -0.055703 0.082959 -0.671 0.502
L1.Salzburg 0.208003 0.042719 4.869 0.000
L1.Steiermark 0.139622 0.056393 2.476 0.013
L1.Tirol 0.058567 0.045491 1.287 0.198
L1.Vorarlberg 0.147127 0.040193 3.660 0.000
L1.Wien 0.119584 0.073912 1.618 0.106
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.389280 0.038649 10.072 0.000
L1.Burgenland -0.004416 0.023696 -0.186 0.852
L1.Kärnten -0.020971 0.012397 -1.692 0.091
L1.Niederösterreich 0.202931 0.049548 4.096 0.000
L1.Oberösterreich 0.230933 0.048805 4.732 0.000
L1.Salzburg 0.036480 0.025132 1.452 0.147
L1.Steiermark -0.015760 0.033176 -0.475 0.635
L1.Tirol 0.089677 0.026762 3.351 0.001
L1.Vorarlberg 0.051138 0.023646 2.163 0.031
L1.Wien 0.043666 0.043483 1.004 0.315
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036763 0.109232 0.172773 0.139160 0.101355 0.081549 0.035718 0.210573
Kärnten 0.036763 1.000000 -0.026193 0.130945 0.049100 0.085104 0.443613 -0.066549 0.089646
Niederösterreich 0.109232 -0.026193 1.000000 0.314085 0.120783 0.274505 0.068453 0.154631 0.292849
Oberösterreich 0.172773 0.130945 0.314085 1.000000 0.213514 0.297288 0.166907 0.138320 0.239431
Salzburg 0.139160 0.049100 0.120783 0.213514 1.000000 0.124147 0.092803 0.105877 0.124743
Steiermark 0.101355 0.085104 0.274505 0.297288 0.124147 1.000000 0.134793 0.108703 0.036741
Tirol 0.081549 0.443613 0.068453 0.166907 0.092803 0.134793 1.000000 0.065000 0.150750
Vorarlberg 0.035718 -0.066549 0.154631 0.138320 0.105877 0.108703 0.065000 1.000000 -0.003331
Wien 0.210573 0.089646 0.292849 0.239431 0.124743 0.036741 0.150750 -0.003331 1.000000